package com.dayuanit.hotal;

import java.util.Date;
import java.util.List;

/**
 * 小票打印机
 */
public class TicktUtil {

    public static final String naemFormat = "\t\t%s";
    public static final String tableTitleFormat = "菜名\t数量\t单价(元)\t 小结";
    public static final String detailFormat = "%s\t%s\t%s\t%s";
    public static final String lineFormat = "------------------------";
    public static final String orderAmountFormat = "总价: \t\t %s";
    public static final String youhuiAmountFormat = "优惠: \t\t %s";
    public static final String payAmountFormat = "实付金额: \t\t %s";
    public static final String timeFormat = "结算时间:  %s";

    public static void print(Restaurant restaurant, double orderAmount, double payAmount, double youhuiAmount, List<OrderDetail> orderDetails ) {
        print(restaurant.getName(), orderAmount, payAmount, youhuiAmount, orderDetails);
    }

    public static void print(String restaurantName, double orderAmount, double payAmount, double youhuiAmount, List<OrderDetail> orderDetails ) {
        // 输出餐馆名称
        System.out.println(String.format(naemFormat, restaurantName));

        // 输出表头
        System.out.println(String.format(tableTitleFormat));

        // 输出商品明细 loop
        for (OrderDetail detail : orderDetails) {
            System.out.println(String.format(detailFormat, detail.getFoodName(), detail.getCount(), detail.getPrice(), detail.getTotalAmount()));
        }

        // 输出分割线
        System.out.println(String.format(lineFormat));

        // 总价
        System.out.println(String.format(orderAmountFormat, orderAmount));

        // 优惠
        System.out.println(String.format(youhuiAmountFormat, youhuiAmount));

        // 实付金额
        System.out.println(String.format(payAmountFormat, payAmount));

        // 结算时间
        System.out.println(String.format(timeFormat, DateUtil.dateToString(new Date())));
    }
}
